/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.oracleandsxnd.erp.seting.web;

import com.oracleandsxnd.erp.common.persistence.Page;
import com.oracleandsxnd.erp.common.persistence.TableSplitResult;
import com.oracleandsxnd.erp.common.web.AjaxResult;
import com.oracleandsxnd.erp.common.web.BaseController;
import com.oracleandsxnd.erp.seting.entity.Company;
import com.oracleandsxnd.erp.seting.entity.CompanyCategory;
import com.oracleandsxnd.erp.seting.service.CompanyCategoryService;
import com.oracleandsxnd.erp.seting.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 往来单位Controller
 * @author 往来单位
 * @version 2019-12-17
 */
@Controller
@RequestMapping(value = "seting_company")
public class CompanyController extends BaseController {

	@Autowired
	private CompanyService companyService;
	@Autowired
	private CompanyCategoryService companyCategoryService;
	@RequestMapping(value = {""})
	public String list(Company company, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<CompanyCategory> companyCategorys= companyCategoryService.findList(new CompanyCategory());
		model.addAttribute("companyCategorys",companyCategorys);
		return "erp/seting/companyList";
	}

	@RequestMapping(value = {"listData"})
	@ResponseBody
	public Object listData(Company company , HttpServletRequest request, HttpServletResponse response){
		Page<Company> page = companyService.findPage(new Page<Company>(request, response), company);
		TableSplitResult<Company> result=new TableSplitResult<Company>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = "save")
	@ResponseBody
	public AjaxResult save(Company company) {

		companyService.save(company);
		return success();
	}

	@RequestMapping(value = "delete")
	@ResponseBody
	public AjaxResult  delete(Company company, RedirectAttributes redirectAttributes) {
		companyService.delete(company);
		return success();
	}

}